using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BikyBall.Graphic
{
    public class ShadowConstructor
    {
        public static VertexPositionNormalTexture[] _vertices = null;
        public static VertexBuffer _vertexBuffer = null;
        public static Texture2D _texture = null;
        public static GraphicProperty Construct()
        {
            const int NUM_TRIANGLES = 2;
            const int NUM_VERTICES = 6;
            if (_vertices == null)
            {
                _vertices = new VertexPositionNormalTexture[NUM_VERTICES];

                // Calculate the position of the vertices on the bottom face.
                Vector3 btmLeftFront = new Vector3(-0.5f, -0.5f, -0.5f);
                Vector3 btmLeftBack = new Vector3(-0.5f, -0.5f, 0.5f);
                Vector3 btmRightFront = new Vector3(0.5f, -0.5f, -0.5f);
                Vector3 btmRightBack = new Vector3(0.5f, -0.5f, 0.5f);

                // Normal vectors for each face (needed for lighting / display)
                Vector3 normalFront = new Vector3(0.0f, 0.0f, 1.0f);
                Vector3 normalBack = new Vector3(0.0f, 0.0f, -1.0f);
                Vector3 normalTop = new Vector3(0.0f, 1.0f, 0.0f);
                Vector3 normalBottom = new Vector3(0.0f, -1.0f, 0.0f);
                Vector3 normalLeft = new Vector3(-1.0f, 0.0f, 0.0f);
                Vector3 normalRight = new Vector3(1.0f, 0.0f, 0.0f);

                // UV texture coordinates
                Vector2 textureTopLeft = new Vector2(0.0f, 0.0f);
                Vector2 textureTopRight = new Vector2(1.0f, 0.0f);
                Vector2 textureBottomLeft = new Vector2(0.0f, 1.0f);
                Vector2 textureBottomRight = new Vector2(1.0f, 1.0f);


                // Add the _vertices for the BOTTOM face. 
                _vertices[2] = new VertexPositionNormalTexture(btmLeftFront, normalTop, textureTopLeft);
                _vertices[1] = new VertexPositionNormalTexture(btmLeftBack, normalTop, textureBottomLeft);
                _vertices[0] = new VertexPositionNormalTexture(btmRightBack, normalTop, textureBottomRight);
                _vertices[5] = new VertexPositionNormalTexture(btmLeftFront, normalTop, textureTopLeft);
                _vertices[4] = new VertexPositionNormalTexture(btmRightBack, normalTop, textureBottomRight);
                _vertices[3] = new VertexPositionNormalTexture(btmRightFront, normalTop, textureTopRight);

                _vertexBuffer = new VertexBuffer(GraphicEngine.Device, VertexPositionNormalTexture.VertexDeclaration, NUM_VERTICES, BufferUsage.WriteOnly);
                _vertexBuffer.SetData(_vertices);
                _texture = GraphicEngine.Content.Load<Texture2D>("ombre");
            }
            GraphicProperty gp = new GraphicProperty();
            gp.Vertices = _vertices;
            gp.NumVertices = NUM_VERTICES;
            gp.NumTriangles = NUM_TRIANGLES;
            gp.PrimitiveType = PrimitiveType.TriangleList;
            gp.VertexBuffer = _vertexBuffer;
            gp.Texture = _texture;
            gp.Effect = new BasicEffect(GraphicEngine.Device);
            gp.Effect.TextureEnabled = true;
            gp.Effect.Texture = _texture;
            gp.Effect.EnableDefaultLighting();
            gp.IndexBuffer = null;
            return gp;
        }
    }
}
